package org.szy.monitor.listener;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjUtil;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.event.EventListener;
import org.szy.monitor.service.UserOnlineService;

import java.time.LocalDateTime;

/**
 * 用户同步活动事件侦听器
 *
 * @author 孙志阳
 * @date 2023-07-05
 * @since 1.0.0
 **/
@Component
public class UserSyncActivityEventListener implements EventListener<SaTokenInfo> {

    @Inject
    private UserOnlineService userOnlineService;

    @Override
    public void onEvent(SaTokenInfo event) {
        if (ObjUtil.isNull(event)) {
            return;
        }

        String token = event.getTokenValue();

        this.userOnlineService.syncActivityTime(token, LocalDateTime.now());
    }

}
